<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%
	String roleId = request.getParameter("roleId");
	String codeId = request.getParameter("codeId");
%>

<html>
	<head>
		<script type="text/javascript">
		
			$(function(){
		        loadGird("frm", 1);
			})
				
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		           row.find(".klId").attr("value",n.id);
		       	   row.find(".klCode").text(n.code);
		           row.find(".klOrgName").text(n.name);
		           row.find(".klOrgShortName").text(n.short_name);
		           row.find(".klRemarks").text(n.remarks);
		           
		           row.attr("id","ready"+i);//改变绑定好数据的行的id
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");//添加到模板的容器中
		       }); 
			}
			
			var delOrgsforRole = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
					alert("移除成功！");
					document.location.reload();
				}
				}
				if(confirm('您确认要删除吗？')){
					//提交form
					document.getElementById("frm").action="<%=path %>/sys/role/delmods";
					$('#frm').ajaxSubmit(options);
				}
			}
			
			var  addOrgsForRole = function(){
				selMultiDept('orgs','orgnames')
				if(document.getElementById("orgs").value!=""){
				    var options = {
						type: 'POST',
						async: false,
						dataType: 'content-type',
						success: function(msg) {
							alert("添加成功！");
							window.location.reload();
						}
					}
				    if(document.getElementById("orgs").value!=""){
						document.getElementById("frm").action="<%=path %>/sys/role/addorgs";
						$('#frm').ajaxSubmit(options);
						document.getElementById("frm").action="<%=path %>/sys/role/showorgs";
				    }
				}
			}
			function goback(){
				window.location = "<%=path%>/sys/role/get/roleList?codeId=<%=codeId %>";
			}
		</script>
	</head>
<body>
	<form name="frm" method="post" style="margin: 0" action="<%=path %>/sys/role/showorgs" id="frm">
		<input type="hidden" name="roleId" value="<%=roleId %>"/>
		<input type="hidden" name="orgs" id="orgs" >
		<input type="hidden" name="orgnames" id="orgnames" >
		<table><tr><td height="2px"></td></tr></table>
		&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#" onclick="addOrgsForRole()" >添加组织机构</a>&nbsp;|&nbsp;
			<a href="#" onclick="delOrgsforRole()" >移除组织机构</a>&nbsp;|&nbsp;
			<a href="#" onclick="goback()" >返回</a>
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px">
						<input type="checkbox" class="allCheck" />
					</td>
					<td nowrap="nowrap">
						机构编码
					</td>
					<td nowrap="nowrap">
						机构名称
					</td>
					<td nowrap="nowrap">
						机构简称
					</td>
					<td nowrap="nowrap">
						备  注
					</td>
				</tr>
			</thead>
			<tbody>
				<tr class="template klId">
					<td width="40px" class="idCheck">
						<input type="checkbox" name="chk" class="klId" />
					</td>
					<td class="klCode niceTable-left"></td>
					<td class="klOrgName niceTable-left"></td>
					<td class="klOrgShortName niceTable-left"></td>
					<td class="klRemarks niceTable-left"></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td align="right" colspan="10" >
						<img class="loading"
							src="<%=imgPath %>/large-loading.gif" width="20px"
							class="hidden" />
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</body>
</html>
